﻿namespace _5._9._04.SortingAlgorithmsComparison
{
    using System;
    using System.Collections;
    using System.Diagnostics;

    class Comparison
    {
        static void Main()
        {
            // http://www.sorting-algorithms.com/

            Console.WriteLine("<<< random values >>>");

            Console.WriteLine("--- int ---");
            PerformanceCheck(new int[] { 3, 5, 3, 5, 1, 4, 4, 9, 33, 1, 13, 15, 11 });

            Console.WriteLine("--- double ---");
            PerformanceCheck(new double[] { 3, 5, 3, 5, 1, 4, 4, 9, 33, 1, 13, 15, 11 });

            Console.WriteLine("--- string ---");
            PerformanceCheck(new string[] { "3", "5", "3", "5", "1", "4", "4", "9", "33", "1", "13", "15", "11" });

            Console.WriteLine("<<< sorted values >>>");

            Console.WriteLine("--- int ---");
            PerformanceCheck(new int[] { 1, 3, 5, 5, 7, 8, 13, 21, 34, 65, 99, 123, 155 });

            Console.WriteLine("--- double ---");
            PerformanceCheck(new double[] { 1, 3, 5, 5, 7, 8, 13, 21, 34, 65, 99, 123, 155 });

            Console.WriteLine("--- string ---");
            PerformanceCheck(new string[] { "1", "3", "5", "5", "7", "8", "13", "21", "34", "65", "99", "123", "155" });

            Console.WriteLine("<<< reversed values >>>");

            Console.WriteLine("--- int ---");
            PerformanceCheck(new int[] { 155, 123, 99, 65, 34, 21, 13, 8, 7, 5, 5, 3, 1 });

            Console.WriteLine("--- double ---");
            PerformanceCheck(new double[] { 155, 123, 99, 65, 34, 21, 13, 8, 7, 5, 5, 3, 1 });

            Console.WriteLine("--- string ---");
            PerformanceCheck(new string[] { "155", "123", "99", "65", "34", "21", "13", "8", "7", "5", "5", "3", "1" });
        }

        static void PrintCollection<T>(T[] collection) where T : IComparable<T>
        {
            for (int i = 0; i < collection.Length; i++)
            {
                Console.Write(collection[i] + " ");
            }

            Console.WriteLine();
        }

        static void PerformanceCheck<T>(T[] collection) where T : IComparable<T>
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            SortingAlgorithms.SelectionSort(collection);
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - selection sort");

            sw.Reset();
            sw.Start();
            SortingAlgorithms.InsertionSort(collection);
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - insertion sort");

            sw.Reset();
            sw.Start();
            SortingAlgorithms.Quicksort(collection, 0, collection.Length - 1);
            sw.Stop();
            Console.WriteLine(sw.Elapsed + " - quick sort");
        }
    }
}